#include <iostream>
#include "creditCard.h" //supposed to be CreditCard.h
#include <cmath>
#include <iomanip>
using namespace std;

double creditCard::clearFV_pmt()const //calc how much Pmt need to make in N periods to clear account (given N, find Pmt)
{
	return (getPV() * pow(1+getR(), getN()) * getR() ) / ( pow(1+getR(), getN()) - 1); // pmt = PV(1+r)^n * r / [(1+r)n-1]
}

void creditCard::setValues(double rate, int n, double pmt, double pv, double fv)
{
	Annuity::setValues(rate, n , pmt, pv , fv);
}

double creditCard::actualPayoff()const
{
	if (((getPV() * getR()) / 12) > getPmt())								//if monthly interest on balance > monthly payment. PV * apr/12 > pmt
		cout << "Error, nothing is going towards debt." << endl;
		return 0;
	return (((getPV() * getR()) / 12) - getPmt());
}

void creditCard::printPayoff()
{
	cout << "Based on your entries of: " << endl;
	cout << "CC Balance amt: $" << getPV() << endl;
	cout << "Monthly nominal Interest Rate(APR/12): " << setprecision(2) << getR() << "%" << endl;
	cout << "With the monthly payment of: $" << getPmt() << endl;
	cout << "$" << actualPayoff() << " is being cleared from your CC debt with the next payment." << endl;
}

void creditCard::printclearPmt()
{
	cout << "Based on your entries of: " << endl;
	cout << "CC Balance amt: $" << getPV() << endl;
	cout << "Monthly norminal Interest Rate(APR/12): " << setprecision(2) << getR() << "%" << endl;
	cout << "In order to pay off your current credit card debt in the requested " << getN() << " months," << endl;
	cout << "Your monthly credit card payment will be: $" << setprecision(5) << clearFV_pmt() << endl;
}

creditCard::creditCard()
{

}